// pages/news/news.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jso: [],
    tiaojian: "",
    inputShowed: false,//搜索控件数据
    inputVal: "",//搜索控件数据
    tabs: ["按a-z排序", "按欠款排序", "按欠货排序"],//顶部导航栏内容
    activeIndex: 0,//导航栏控件数据
    sliderOffset: 0,//导航栏控件数据
    sliderLeft: 0,//导航栏控件数据
    qianhuo: true,//客户状态是否欠货
    qiankuan: false,//客户状态是否欠款
    shopid: ''//商户id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      shopid: wx.getStorageSync("shopid")
    })
    console.log(that.data.shopid);
    wx.request({
      url: 'https://www.wenzhixinxi.com/phptest/orderby_atoz.php', //你的后台地址
      data: {
        shopid: that.data.shopid
      },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {
        that.setData({
          qiankuan: true,
          qianhuo: true
        })
        var jso = res.data.jsonObj;
        console.log(res);
        console.log("data=" + res.data);
        that.setData({
          jso: jso,
        })
        console.log("jso=" + jso);
      }
    })
  },

  onItemClick: function (event) {//点击新闻跳转页面
    console.log('跳转客户页面')
  },

  getmsg: function (e) {
    console.log("121" + e.detail.value)
    this.setData({
      tiaojian: e.detail.value
    })
    console.log(this.data.tiaojian)
  },

  search: function () {//搜索页面
    console.log("输入的数据" + this.data.tiaojian)
    var that = this;
    wx.request({
      url: 'https://www.wenzhixinxi.com/phptest/searchuser.php', //你的后台地址
      data: {
        name: that.data.tiaojian,
        shopid: that.data.shopid,
      },
      header: {
        'content-type': 'application/json'
      },

      success: function (res) {
        var jso = res.data.jsonObj;
        console.log(res);
        console.log("data=" + res.data);
        that.setData({
          jso: jso,
        })
        console.log("jso=" + jso);
        if (that.data.activeIndex == 0) {
          that.setData({
            qiankuan: true,
            qianhuo: true
          })
        }
        else if (that.data.activeIndex == 1) {
          that.setData({
            qiankuan: true,
            qianhuo: false
          })
        }
        else {
          that.setData({
            qiankuan: false,
            qianhuo: true
          })
        }

      }
    })
  },

  //搜索控件事件
  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value
    });
  },

  //顶部导航栏触发事件
  tabClick: function (e) {//事件触发
    this.setData({//前端点击导航返回结果接收
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id//表示点击的第几个标签
    });
    console.log(this.data.tabs[this.data.activeIndex])
    var that = this;
    if (that.data.activeIndex == 0) {
      console.log(that.data.shopid);
      wx.request({
        url: 'https://www.wenzhixinxi.com/phptest/orderby_atoz.php', //你的后台地址
        data: {
          shopid: that.data.shopid
        },
        header: {
          'content-type': 'application/json'
        },

        success: function (res) {
          that.setData({
            qiankuan: true,
            qianhuo: true
          })
          var jso = res.data.jsonObj;
          console.log(res);
          console.log("data=" + res.data);
          that.setData({
            jso: jso,
          })
          console.log("jso=" + jso);
        }
      })
    }
    else if (this.data.activeIndex == 1) {
      wx.request({
        url: 'https://www.wenzhixinxi.com/phptest/orderby_shortmoney.php', //你的后台地址
        data: {
          shopid: that.data.shopid
        },
        header: {
          'content-type': 'application/json'
        },

        success: function (res) {
          that.setData({
            qiankuan: true,
            qianhuo: false
          })
          var jso = res.data.jsonObj;
          console.log(res);
          console.log("data=" + res.data);
          that.setData({
            jso: jso,
          })
          console.log("jso=" + jso);

        }
      })
    }
    else {
      wx.request({
        url: 'https://www.wenzhixinxi.com/phptest/orderby_shortgoods.php', //你的后台地址
        data: {
          shopid: that.data.shopid
        },
        header: {
          'content-type': 'application/json'
        },

        success: function (res) {
          that.setData({
            qiankuan: false,
            qianhuo: true
          })
          var jso = res.data.jsonObj;
          console.log(res);
          console.log("data=" + res.data);
          that.setData({
            jso: jso,
          })
          console.log("jso=" + jso);
        }
      })
    }
  }
})